package com.cug.campus_sh_market_server.interceptor;

import com.cug.campus_sh_market_server.util.UserContext;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ttxxi
 **/
public class UserContextInterceptor implements HandlerInterceptor {

    private static final String TOKEN_NAME = "Authorization";


    @Override
    public boolean preHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
        return true;
    }


    @Override
    public void afterCompletion(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull Object handler, Exception ex) throws Exception {
        //!!!!很重要，每一次结束后必须remove掉，不然会内存泄露
        UserContext.remove();
    }
}
